package smecta.client.print.domain.query;

import com.github.pagehelper.PageInfo;
import org.apache.commons.collections.CollectionUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class PageDTO<T> implements Serializable {

    private static final long serialVersionUID = 5307418198820842303L;
    /**
     *
     */

    private Integer pageNo = 0;

    private Integer totalNum = 0;

    private Integer totalPageNum = 0;

    private Integer pageSize = 10;

    private List<T> list = new ArrayList<>();

    public PageDTO() {
    }

    public PageDTO(PageInfo pageInfo) {
        this.pageNo = pageInfo.getPageNum();
        this.totalNum = (int) pageInfo.getTotal();
        this.totalPageNum = pageInfo.getPages();
        this.pageSize = pageInfo.getPageSize();
        if (CollectionUtils.isNotEmpty(pageInfo.getList())){
            this.list = pageInfo.getList();
        }
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getTotalNum() {
        return totalNum;
    }

    public void setTotalNum(Integer totalNum) {
        this.totalNum = totalNum;
        if (this.totalNum == 0) {
            this.totalPageNum = 0;
        } else {
            this.totalPageNum = this.totalNum / this.pageSize;
            if (this.totalNum % this.pageSize > 0) {
                this.totalPageNum++;
            }
        }
    }

    public Integer getTotalPageNum() {
        return totalPageNum;
    }

    public void setTotalPageNum(Integer totalPageNum) {
        this.totalPageNum = totalPageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

}
